use std::collections::HashMap;
fn vec1(){
    let mut v: Vec<i32> = Vec::new();
    let v2 = vec![1, 2, 3];
    v.push(5);
    v.push(6);
    v.push(7);
    v.push(8);
    
    let third: &i32 = &v[2];
    println!("The third element is {}", third);

    match v.get(2) {
        Some(third) => println!("The third element is {}", third),
        None => println!("There is no third element."),
    }
    // let does_not_exist = &v[100];
    // let does_not_exist = v.get(100);
    // println!("does_not_exist is {}", does_not_exist);//Option<&i32>` cannot be formatted with the default formatter

    // let first = &v[0];

    // v.push(6);

    // println!("The first element is: {}", first);

    for i in &v {
        println!("{}", i);
    }

    for i in &mut v {
        *i += 50;
    }
    for i in &v {
        println!("{}", i);
    }
    enum SpreadsheetCell {
        Int(i32),
        Float(f64),
        Text(String),
    }

    let row = vec![
        SpreadsheetCell::Int(3),
        SpreadsheetCell::Text(String::from("blue")),
        SpreadsheetCell::Float(10.12),
    ];

}
fn str1(){
    let mut s = String::from("hello");

    s.push_str(", world!"); // push_str() appends a literal to a String

    println!("{}", s); // This will print `hello, world!`

}
fn map(){

    let mut scores = HashMap::new();
    scores.insert(String::from("Blue"), 10);
    scores.insert(String::from("Yellow"), 50);

    let teams = vec![String::from("Blue"), String::from("Yellow")];
    let initial_scores = vec![10, 50];

    let z=teams.into_iter().zip(initial_scores.into_iter());
    println!("{:?}",z);

    let mut scores: HashMap<_, _> =
        z.collect();
    println!("{:?}",scores);
    let team_name = String::from("Blue");
    let score = scores.get(&team_name);
    println!("team {}'s score:{:?}",team_name,score);
    scores.insert(String::from("Blue"), 10);
    scores.insert(String::from("Blue"), 25);
    scores.entry(String::from("Yellow")).or_insert(50);
    scores.entry(String::from("Blue")).or_insert(50);

    println!("{:?}", scores);
    for (key, value) in &scores {
        println!("{}: {}", key, value);
    }

    let text = "hello world wonderful world";
    let mut map = HashMap::new();
    for word in text.split_whitespace() {
        let count = map.entry(word).or_insert(0);
        *count += 1;
    }
    println!("{:?}", map);

    let field_name = String::from("Favorite color");
    let field_value = String::from("Blue");

    let mut map = HashMap::new();
    map.insert(field_name, field_value);//moved to map
    // println!("{:?}",field_name);
}
pub fn main(){
    // vec1();
    // str1();
    map();
}